package com.swipemaster.activities;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;

import com.google.analytics.tracking.android.EasyTracker;
import com.swipemaster.R;
import com.swipemaster.common.AdMobFullscreen;

public class FullscreenActivity extends Activity implements OnClickListener
{
	public static final String EXTRAS_KEY = "fullscreen_id";

	private Button exitButton;
	private ViewGroup root;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		EasyTracker.getInstance().activityStart(this);

		setTheme(android.R.style.Theme_Translucent_NoTitleBar);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		setContentView(R.layout.fullscreen);

		exitButton = (Button) findViewById(R.id.fullscreen_exit);
		exitButton.setOnClickListener(this);

		root = (ViewGroup) findViewById(R.id.fullscreen_layout);

		final String fullscreenId = getIntent().getStringExtra(EXTRAS_KEY);
		final AdMobFullscreen fullscreen = MainActivity.fullscreens.get(fullscreenId);
		if (root == null || fullscreen == null)
		{
			finish();
			return;
		}
		root.addView(fullscreen.adView);
	}

	@Override
	public void onClick(View view)
	{
		if (view == exitButton)
		{
			finish();
		}
	}

	@Override
	protected void onStop()
	{
		super.onStop();
		EasyTracker.getInstance().activityStop(this);
	}

	@Override
	protected void onDestroy()
	{
		root.removeAllViews();
		super.onDestroy();
	}
}
